<?php
namespace app\admin\model;

use think\Model;
use think\Db;

class StRollOutModel extends Model{
	// 确定链接表名
    protected $name = 'st_roll_out';

	/**
	 * [获取信息]
	 */
	public function getInfoByWhere($where=[]){
		$Info =  $this->where($this->whereSchool())->where($where)->order('id desc')->paginate(20);
		foreach($Info as $k => $v){
			$Info[$k]['st_name'] = DB::name('student')->where('id',$v['st_id'])->value('name');
		}
		return $Info;
	}

	/**
	 * [教务老师只能看见自己所管理的学校的学生]
	 */
	public function whereSchool(){
		$school_id = DB::name('teacher')->where('user_id',session('id'))->value('school_id');
		if($school_id == ''){
			// 如果学校ID为空则证明登录者不是教务老师，则能看见所有学员
			return null;
		}
		$idArr = explode(",",$school_id);
		$this->where(function($query)use($idArr){
			foreach($idArr as $v){
				$query->whereOr('school_id',$v);
			}
		});
	}
}
